//沟通计划
<template>
  <!-- 普通表单一行多列，注意必须增加el-form属性 :inline="true" -->
  <table-row-detail-dialog
    ref="detailDialog"
    @confirm="handleConfirm"
    dialogWidth="60%"
  >
    <div class="dialog-body">
      <el-form
        ref="form"
        :inline="true"
        label-position="left"
        :label-width="standFormLeftWidth"
        :model="formData"
      >
        <form-item-group
          :form-data="formData"
          :label-width="standFormLeftWidth"
          ref="formGroup"
          @change="change"
        ></form-item-group>
      </el-form>
    </div>
  </table-row-detail-dialog>
</template>

<script>
import TableRowDetailDialog from '@/components/TableRowDetailDialogNew/index';
import FormItemGroup from '@/components/FormItemGroupNew/index';
import { add, edit, detail } from '@/api/project/alarmHandling';
import DetailAction from '@/views/_mixins/detail-action';
// import dayjs from 'dayjs';
// import 'dayjs/locale/zh-cn'; // 导入中文语言包
export default {
  name: 'ItemDetail',
  mixins: [DetailAction],
  components: {
    TableRowDetailDialog,
    FormItemGroup
  },
  props: {},
  data() {
    return {
      standFormLeftWidth: '120px',
      arrBusinessUnit: [],
      emerFaultId: ''
    };
  },
  computed: {},
  created() {
    // dayjs.locale('zh-cn');
    // this.getBusinessUnitListDetail();
  },
  /* watch: {
    dialogType: {
      handler(val) {
        console.log('now mode:', val);
        if (val === 'add') {
          this.formData.goalYearMonth.value = dayjs(new Date()).format(
            'YYYY-MM'
          );
        }
      },
      immediate: true
    }
  }, */
  methods: {
    //表单单项验证
    validateField(fieldName) {
      this.$refs.form.validateField(fieldName);
    },
    //初始化表单数据
    initFormData() {
      this.formData = {};
    },
    /**
     * 获取记录详情
     * 填充表单数据对象
     * */
    getDetail(data) {
      this.emerFaultId = data.emerFaultId;
      detail(data.emerFaultId).then(res => {
        for (let key in this.formData) {
          this.formData[key].value = res[key] || '';
        }
        // let itemIndex = this.arrBusinessUnit.findIndex(findIndexItem =>
        //   findIndexItem.value.includes(res.businessUnit)
        // );
        //   let findItem = this.arrBusinessUnit[itemIndex];
        //   this.formTop.businessUnit.value = findItem.value;
      });
    },
    /**
     * 对话框确认按钮响应
     * */
    handleConfirm() {
      let data = this.$refs.formGroup.checkValue();
      if (!data) {
        return false;
      }
      console.log(data);

      if (this.dialogType === 'add') {
        this.submitAdd(data);
      } else {
        this.submitEdit(data);
      }
    },
    /**
     * 添加记录
     * 校验表单数据后，add接口
     */
    async submitAdd(data) {
      add(data).then(this.submitSuccess);
    },
    /**
     * 记录详情数据编辑提交
     * 校验表单数据后，调用edit接口
     */
    submitEdit(data) {
      edit(this.emerFaultId, data).then(this.submitSuccess);
    },
    handleCancel() {
      this.$refs.detailDialog.hide();
    },
    change(value, row) {}
  }
};
</script>

<style lang="scss" scoped></style>
